package com.example.lenovo.weiyi;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.com.ruanmeng.demon.CommonM;
import com.com.ruanmeng.utils.CommonUtil;
import com.com.ruanmeng.utils.Params;
import com.com.ruanmeng.utils.PreferencesUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.Request;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import nohttp.CallServer;
import nohttp.CustomHttpListener;
import share.Const;
import share.HttpIP;

public class FaQiLunTanActivity extends BaseActivity {

    @BindView(R.id.ed_falt_title)
    EditText edFaltTitle;
    @BindView(R.id.ed_fqlt_content)
    EditText edFqltContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fa_qi_lun_tan);
        ButterKnife.bind(this);
        ChangLayTitle("发起论坛");
        LayBack();
    }

    public void doClick(View v) {
        switch (v.getId()) {
            case R.id.bt_fqlt_sure:
                if (TextUtils.isEmpty(edFaltTitle.getText().toString())) {
                    CommonUtil.showToask(FaQiLunTanActivity.this, "请输入标题！");
                    return;
                }
                if (TextUtils.isEmpty(edFqltContent.getText().toString())) {
                    CommonUtil.showToask(FaQiLunTanActivity.this, "请输入内容！");
                    return;
                }
                getData();
                break;
        }
    }

    private void getData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.FaBuLunTan, Const.POST);
        mRequest.addHeader("token", PreferencesUtils.getString(FaQiLunTanActivity.this, "uid"));
        mRequest.add("content", edFqltContent.getText().toString());
        mRequest.add("title", edFaltTitle.getText().toString());
        CallServer.getRequestInstance().add(FaQiLunTanActivity.this, 0, mRequest,
                new CustomHttpListener(FaQiLunTanActivity.this, true, CommonM.class) {

                    @Override
                    public void doWork(Object data, boolean isOne) {
                        CommonM model = ((CommonM) data);
                        Params.fqlt = 1;
                        finish();
                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                        CommonUtil.showToask(FaQiLunTanActivity.this, obj.getString("msg"));
                    }
                }, true, true);
    }
}
